package com.wss.guli.product.web;

import com.wss.guli.product.entity.CategoryEntity;
import com.wss.guli.product.service.CategoryService;
import com.wss.guli.product.vo.Catelog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {
    @Autowired
    CategoryService categoryService;

    /**
     * 首页
     * @return
     */
    @GetMapping({"/","/index.html"})
    public String indexPage(Model model){
        //获取所有一级分类数据
  List<CategoryEntity>categoryEntities= categoryService.getLevel1Categorys();
         model.addAttribute("categorys",categoryEntities);
        return "index";
    }

    //index/catalog.json
    /**
     * 获取二级分类和三级分类数据
     */
    @ResponseBody
    @GetMapping("/index/catalog.json")
    public  Map<String, List<Catelog2Vo>>getCatalogJson(){
        Map<String, List<Catelog2Vo>> map=categoryService.getCatalogJson();
        return map;
    }
}
